const http = require("http");

let options = {
    hostname: "localhost",
    port: 3000,
    pathname: "/postdata",
    //默认是get请求
    method: "POST",
    // headers:
}

const req = http.request(options, (res) => {
    let str = ""
    res.on("data", (chunk) => {
        str += chunk;
    })
    res.on("end", () => {
        console.log(str);
    })
})

let userInfor = {
    "username": "zhangsan",
    "age": 20
}

req.write(JSON.stringify(userInfor));
req.end();